package com.dzx.currentency.aqs;

import java.util.concurrent.*;

/**
 * @author DuanZhaoXu
 * @ClassName:
 * @Description:
 * @date 2018年11月20日 14:22:15
 */
public class FutureExample {


    static class MyTask implements Callable<String> {
        @Override
        public String call() throws Exception {
            return "10000";
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //Future
        ExecutorService service = Executors.newCachedThreadPool();
        Future<String> future = service.submit(new MyTask());
        String result = future.get();
        System.out.println(result);

        //FutureTask
        FutureTask<String> futureTask = new FutureTask<String>(() -> {
            return "10000";
        });
        new Thread(futureTask).start();
        System.out.println(futureTask.get());


    }
}
